//app.js
App({
  onLaunch: function () {
    //调用API从本地缓存中获取数据
    // var logs = wx.getStorageSync('logs') || []
    // logs.unshift(Date.now())
    // wx.setStorageSync('logs', logs)
    // wx.setStorageSync('globalData', this.globalData);
    if (wx.openBluetoothAdapter) {
      wx.openBluetoothAdapter()
    } else {
      // 如果希望用户在最新版本的客户端上体验您的小程序，可以这样子提示
      wx.showModal({
        title: '提示',
        content: '当前微信版本过低，无法使用该功能，请升级到最新微信版本后重试。'
      })
    }
  },
  getUserInfo:function(cb){
    var that = this
    if(this.globalData.userInfo){
      typeof cb == "function" && cb(this.globalData.userInfo)
    }else{
      //调用登录接口
      wx.login({
        success: function (res) {
          // console.log(res);
          that.globalData.code = res.code;
          if(res.code){
            wx.request({
              url: 'https://api.weixin.qq.com/sns/jscode2session',
              data: {
                "appid":"wx6e5031d45303c32b",
                "secret":"ea9813be1121a9f2546fe0d17bcaf37c",
                "js_code":res.code,
                "grant_type":"authorization_code"
              },
              method: 'GET',
              // header: {}, // 设置请求的 header
              success: function(res){
                // console.log(res.data.openid);
                // 生成唯一sessionid
                // wx.setStorageSync('sessionid', "sessid=" + res.data.openid);
                wx.setStorageSync('sessionid', "sessid=71157b55-816b-4300-91b8-5bce819f58ab")
                // success
              },
              fail: function(res) {
                // fail
              },
              complete: function(res) {
                // complete
              }
            })
          }else {
          console.log('获取用户登录态失败！' + res.errMsg)
        }
          wx.getUserInfo({
            success: function (res) {
              // that.globalData.userInfo = res.userInfo;
              typeof cb == "function" && cb(that.globalData.userInfo)
              wx.setStorageSync('userInfo', res.userInfo);
            }
          });
        }
      })
    }
  },
  globalData:{
    userInfo:null,
    code:null,    
    // 后台地址
    API:'http://139.224.206.114/conferenceSystem'
  }
})